package com.sright.bcard.content.biz.service;

import com.aliyuncs.exceptions.ClientException;
import com.sright.bcard.common.service.share.dto.LoginUser;
import com.sright.bcard.common.service.share.utils.DataConvertUtils;
import com.sright.bcard.content.dal.dao.UserDAO;
import com.sright.bcard.content.dal.entity.UserDO;
import com.sright.bcard.common.service.share.dto.content.AdminDTO;
import com.sright.bcard.common.service.share.dto.content.CardDTO;
import com.sright.bcard.common.service.share.dto.content.UserDTO;
import com.sright.bcard.content.share.service.SmsService;
import com.sright.bcard.content.biz.manager.UserManager;
import com.sright.bcard.content.share.request.CardSaveParam;
import com.sright.bcard.content.share.service.UserService;
import com.sright.bcard.user.share.request.TokenParam;
import com.sright.bcard.enterprise.share.request.CardListParam;
import com.sright.common.response.SrightResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.ParseException;

@Component
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserManager userManager;

    @Autowired
    private SmsService smsService;

    @Autowired
    private UserDAO userDAO;

    @Override
    public SrightResponse save(CardSaveParam param) {
        return SrightResponse.defaultSuccess(userManager.save(param));
    }

    @Override
    public SrightResponse getJoinCount(LoginUser loginUser) {
        return SrightResponse.defaultSuccess(userManager.getJoinCount(loginUser));
    }

    @Override
    public SrightResponse smsSend(AdminDTO adminDTO) throws ClientException {
        return SrightResponse.defaultSuccess(smsService.smsSend(adminDTO));
    }

    @Override
    public SrightResponse resetPassword(AdminDTO adminDTO) {
        return SrightResponse.defaultSuccess(userManager.resetPassword(adminDTO));
    }

    @Override
    public SrightResponse checkCode(AdminDTO adminDTO) {
        return SrightResponse.defaultSuccess(userManager.checkCode(adminDTO));
    }

    @Override
    public SrightResponse contactsMobile(String mobile) {
        return SrightResponse.defaultSuccess(userManager.contactsMobile(mobile));
    }

    @Override
    public SrightResponse<Integer> unbind(CardDTO cardDTO) {
        return SrightResponse.defaultSuccess(userManager.unbind(cardDTO));
    }

    @Override
    public SrightResponse getSetting(Long enterpriseId) {
        return SrightResponse.defaultSuccess(userManager.getSetting(enterpriseId));
    }

    @Override
    public SrightResponse deleteCard(Long id) {
        return SrightResponse.defaultSuccess(userManager.deleteCard(id));
    }

    @Override
    public SrightResponse getUserInfo(TokenParam tokenParam) {
        return SrightResponse.defaultSuccess(userManager.getUserInfo(tokenParam));
    }

    @Override
    public SrightResponse cardList(CardListParam cardListParam) throws ParseException {
        return SrightResponse.defaultSuccess(userManager.cardList(cardListParam));
    }

    @Override
    public SrightResponse userList(CardListParam cardListParam) {
        return SrightResponse.defaultSuccess();
    }

    @Override
    public Boolean updateUser(UserDTO userDTO) {
        UserDO userDO = new UserDO();
        DataConvertUtils.convertDTO2DO(userDTO, userDO);
        return userDAO.updateSelective(userDO);
    }

    @Override
    public SrightResponse userDetail(Long id) {
        return SrightResponse.defaultSuccess(userManager.userDetail(id));
    }

    @Override
    public SrightResponse updateCard(CardSaveParam param) {
        return SrightResponse.defaultSuccess(userManager.updateCard(param));
    }

    @Override
    public SrightResponse expireDays(Long enterpriseId) {
        return SrightResponse.defaultSuccess(userManager.expireDays(enterpriseId));
    }

    @Override
    public void updateCheckStatus(Long cardUserId, Integer checkStatus) {
        userManager.updateCheckStatus(cardUserId,checkStatus);
    }
}
